public static class IntExt
{
    public static byte[] ToByteArray(this int value, int length)
    {
        var retval = new byte[length];
        for (int i = 0; i < length; i++)
        {
            retval[length - 1 - i] = (byte)(value & 0xFF);
            value = value >> 8;
        }
        return retval;
    }
}